

            (function ($) {
              $.getUrlParam = function (name) {
                  var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
                  var r = window.location.search.substring(1).match(reg);
                  if (r != null) return decodeURI(r[2]); return null;
              }
          })(jQuery);
function doSearch(_key) {
  axios.get(host+ '/dic/'+_key)
  .then( (res)=> {
    let list = []
    if (res.data.code != 200) {
        console.log('查找失败！原因：查无此码');
        alert('查找失败！原因：查无此码')
        return
    }
    
    let _ordata = res.data.data
    list.push(
      _ordata
    )
    let htmlCode = ''
    console.log(list);
    for (let i = 0 ; i < list.length; i++) {
     
        htmlCode += `
        <div class="result-box">
        <div>
        <div><span class="fc-gray">字头：</span><span class="fb-6">${list[i].org}</span></div>
        <div><span class="fc-gray">编码：</span><span class="fb-6">${list[i].code}</span></div>
        <div><span class="fc-gray">拆分：</span><span class="fb-6">${list[i].diff}</span></div>
        <div><span class="fc-gray">拼音：</span><span class="fb-6">${list[i].py}</span></div>
        <div><span class="fc-gray">U 码：</span><span class="fb-6">${list[i].uini}</span></div>


        <div><span class="fc-gray"> 字统：</span><span class="fb-6"><a href="${list[i].zits}" target="_blank" >查看字统</a></span></div>
        <div><span class="fc-gray">叶典：</span><span class="fb-6"><a href="${list[i].yets}" target="_blank" >查看叶典</a></span></div>
      

             </div>
             </div>
        `
    }
    $('.result').html(htmlCode)
  })
}
  $(document).ready(function(){
    let list = []
    let sw = null
    sw = ($.getUrlParam('sw'))
    console.log(sw);
    if (sw) {
      doSearch(sw)

      $('#exampleInputName2').val(sw)
    }
    $(".btn").click(function(){
        list = []
        let _key = $('#exampleInputName2').val()
        _key = _key.replace(/\s*/g,"");
        let mode = $('.form-check-input').is(':checked'); 
        console.log(mode);
        $('#exampleInputName2').val(_key)
        if (!mode) {
          axios.get(host+ '/dic/'+_key)
          .then( (res)=> {
            if (res.data.code != 200) {
                console.log('查找失败！原因：查无此码');
                alert('查找失败！原因：查无此码')
                return
            }
            
            let _ordata = res.data.data
            list.push(
              _ordata
            )
            let htmlCode = ''
            for (let i = 0 ; i < list.length; i++) {
             
                htmlCode += `
                <div class="result-box">
                <div>
                <div><span class="fc-gray">字头：</span><span class="fb-6">${list[i].org}</span></div>
                <div><span class="fc-gray">编码：</span><span class="fb-6">${list[i].code}</span></div>
                <div><span class="fc-gray">拆分：</span><span class="fb-6">${list[i].diff}</span></div>
                <div><span class="fc-gray">拼音：</span><span class="fb-6">${list[i].py}</span></div>
                <div><span class="fc-gray">U 码：</span><span class="fb-6">${list[i].uini}</span></div>


                <div><span class="fc-gray"> 字统：</span><span class="fb-6"><a href="${list[i].zits}" target="_blank" >查看字统</a></span></div>
                <div><span class="fc-gray">叶典：</span><span class="fb-6"><a href="${list[i].yets}" target="_blank" >查看叶典</a></span></div>
              

                     </div>
                     </div>
                `
            }
            $('.result').html(htmlCode)
          })
        }else {
        var dic = {};
        _key = _key
        .split("")
        .reduce(function(total,next){
            if (!(next in dic)){
                dic[next] = true;
                total += next;
            }
            return total;
        },"")
      
        for (let i = 0 ; i < _key.length; i++) {
            axios.get(host+'/dic/'+_key[i])
              .then( (res)=> {
                if (res.data.code != 200) {
                    console.log('查找失败！原因：查无此码');
                    alert('查找失败！原因：查无此码')
                    return
                }
                
                let _ordata = res.data.data
                list.push(
                  _ordata
                )
                let htmlCode = ''
                for (let i = 0 ; i < list.length; i++) {
                
                    htmlCode += `
                    <div class="result-box">
                    <div>
                    <div><span class="fc-gray">字头：</span><span class="fb-6">${list[i].org}</span></div>
                    <div><span class="fc-gray">编码：</span><span class="fb-6">${list[i].code}</span></div>
                    <div><span class="fc-gray">拆分：</span><span class="fb-6">${list[i].diff}</span></div>
                    <div><span class="fc-gray">拼音：</span><span class="fb-6">${list[i].py}</span></div>
                    <div><span class="fc-gray">U 码：</span><span class="fb-6">${list[i].uini}</span></div>
  

                    <div><span class="fc-gray"> 字统：</span><span class="fb-6"><a href="${list[i].zits}" target="_blank" >查看字统</a></span></div>
                    <div><span class="fc-gray">叶典：</span><span class="fb-6"><a href="${list[i].yets}" target="_blank" >查看叶典</a></span></div>
                  

                         </div>
                         </div>
                    `
                }
                $('.result').html(htmlCode)
              })
        }}
        
    });
    
    $("input").keydown(function(event){
      if (event.which == 13) {
        list = []
        let _key = $('#exampleInputName2').val()
        let mode = $('.form-check-input').is(':checked'); 
        console.log(_key);
        if (!mode) {
          axios.get(host+'/dic/'+_key).then( (res)=> {
            console.log(res);
            if (res.data.code != 200) {
                console.log('查找失败！原因：查无此码');
                alert('查找失败！原因：查无此码')
                return
            }
            
            let _ordata = res.data.data
            list.push(
              _ordata
            )
            let htmlCode = ''
            for (let i = 0 ; i < list.length; i++) {
                htmlCode += `
                <div class="result-box">
                <div>
                <div><span class="fc-gray">字头：</span><span class="fb-6">${list[i].org}</span></div>
                <div><span class="fc-gray">编码：</span><span class="fb-6">${list[i].code}</span></div>
                <div><span class="fc-gray">拆分：</span><span class="fb-6">${list[i].diff}</span></div>
                <div><span class="fc-gray">拼音：</span><span class="fb-6">${list[i].py}</span></div>
                <div><span class="fc-gray">U 码：</span><span class="fb-6">${list[i].uini}</span></div>


                <div><span class="fc-gray"> 字统：</span><span class="fb-6"><a href="${list[i].zits}" target="_blank" >查看字统</a></span></div>
                <div><span class="fc-gray">叶典：</span><span class="fb-6"><a href="${list[i].yets}" target="_blank" >查看叶典</a></span></div>
              

                     </div>
                     </div>
                `
            }
            $('.result').html(htmlCode)
          })
        }else
        {
          var dic = {};
          _key = _key.replace(/\s*/g,"");
          $('#exampleInputName2').val(_key)
          _key = _key
          .split("")
          .reduce(function(total,next){
              if (!(next in dic)){
                  dic[next] = true;
                  total += next;
              }
              return total;
          },"")

        for (let i = 0 ; i < _key.length; i++) {
            axios.get(host+'/dic/'+_key[i])
              .then( (res)=> {
                if (res.data.code != 200) {
                    console.log('查找失败！原因：查无此码');
                    alert('查找失败！原因：查无此码')
                    return
                }
                
                let _ordata = res.data.data
                list.push(
                  _ordata
                )
                let htmlCode = ''
                for (let i = 0 ; i < list.length; i++) {
                    htmlCode += `
                    <div class="result-box">
                    <div>
                    <div><span class="fc-gray">字头：</span><span class="fb-6">${list[i].org}</span></div>
                    <div><span class="fc-gray">编码：</span><span class="fb-6">${list[i].code}</span></div>
                    <div><span class="fc-gray">拆分：</span><span class="fb-6">${list[i].diff}</span></div>
                    <div><span class="fc-gray">拼音：</span><span class="fb-6">${list[i].py}</span></div>
                    <div><span class="fc-gray">U 码：</span><span class="fb-6">${list[i].uini}</span></div>
  

                    <div><span class="fc-gray"> 字统：</span><span class="fb-6"><a href="${list[i].zits}" target="_blank" >查看字统</a></span></div>
                    <div><span class="fc-gray">叶典：</span><span class="fb-6"><a href="${list[i].yets}" target="_blank" >查看叶典</a></span></div>
                  

                         </div>
                         </div>
                    `
                }
                $('.result').html(htmlCode)
              })
        }
        
     
          }}
    });
  });